import { createStore } from 'redux'
const detailsUrl = "http://101.35.142.7:4981"
const initState = {
    assestURL: detailsUrl,
    uname: "请先登录",
    isOkPwd: false,
    token: "",
    skills: null,
    avatar: `${detailsUrl}/public/image/avatar/default_avatar.png`
}

const reducer = (state = initState, action) => {
    // 根据type的值进行不同的操作
    switch (action.type) {
        case "updateUame":
            // 修改名字
            return { ...state, uname: action.uname }
        case "updateToken":
            // 修改token
            return { ...state, token: action.token }
        case "updateIsOkPwd":
            // 修改时间
            return { ...state, isOkPwd: action.isOkPwd }
        case "addSkills":
            // 添加数组新的一项
            return { ...state, skills: [...state.skills, action.skill] }
        case "updateSkills":
            // 替换
            return { ...state, skills: action.skill }
        case "updateAvatar":
            // 修改头像
            return {
                ...state,
                avatar: action.avatarimg
            }
        default:
            return state  //默认导出全部
    }
}
export const store = createStore(reducer)